package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqGeneralValueResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;

import java.util.List;

public class DeviceRestartReceiver implements Receiver {


    @Override
    public String parseMessage(String data) {
        //*WT,800115470000876,V4,R1,173522,173523,V,0.0000,S,0.0000,W,0.00,0,030621,FFFDFFFF#
        String[] split = data.split(",");
        String imei=split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber=split[4];
        String time=split[5];//设备返回指令时间（时分秒）
        String lat = split[7];
        String lng = split[9];
        String speed = split[11];
        String orientation = split[12];
        String date = split[13];//日月年
        String deviceStatus = split[14];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqGeneralValueResult mqGeneralValueResult = new MqGeneralValueResult();
        mqGeneralValueResult.setDeviceTime(time);
        mqGeneralValueResult.setImei(imei);
        mqGeneralValueResult.setDeviceStatus(deviceStatus);
        mqGeneralValueResult.setDeviceDate(date);
        mqGeneralValueResult.setCommandNumber(commandNumber);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqGeneralValueResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().reStartDeviceResponse(mqGeneralValueResult);
        return imei;
    }

}
